package com.example.ymm.modules1.service.impl.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ymm.base.BaseServiceImpl;
import com.example.ymm.model.TableList;
import com.example.ymm.model.YmPageDto;
import com.example.ymm.modules1.entity.my.user.DbError;
import com.example.ymm.modules1.mapper.my.user.DbErrorMapper;
import com.example.ymm.modules1.query.DbErrorQueryCriteria;
import com.example.ymm.modules1.service.user.DbErrorService;
import com.example.ymm.util.QueryHelpPlus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@Slf4j
public class DbErrorServiceImpl extends BaseServiceImpl<DbErrorMapper, DbError> implements DbErrorService {

    @Override
    public TableList<DbError> list(DbErrorQueryCriteria criteria, YmPageDto pageDto) {
        IPage<DbError> page = new Page<DbError>(pageDto.getPage(),pageDto.getPageSize());
        baseMapper.selectPage(page, QueryHelpPlus.getPredicate(DbError.class, criteria));
        TableList<DbError> tableList=new TableList(page);
        return tableList;
    }

    public List<DbError> queryAll(DbErrorQueryCriteria criteria) {
        QueryWrapper predicate = QueryHelpPlus.getPredicate(DbError.class, criteria);
        predicate.orderByDesc("create_time");
        List<DbError> result =baseMapper.selectList(predicate);
        return result;
    }

    @Override
    public void addError(DbError error) {
//        String userId = getUserId();
        String userName = getUserName();
        error.setUserName(userName);
        saveOrUpdate(error);
    }
}
